<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="com.google.gdata.data.calendar.CalendarEventEntry" %>
<%@page import="java.util.List"%>
<%@page import="ar.edu.itba.bundundu.domain.BundunduEvent"%>

<style>
	.event{
		-moz-border-radius: 2px;
		color: white;
		visibility: visible;
	}
</style>
<script>
<!--
function showEvent(id)
{

	var i=1;
	var event;
	while(event= document.getElementById(id + i)){
		if(event.getStyle('visibility') == 'hidden')
        {
			event.setStyle('visibility', 'visible');
        }
        else
        {
        	event.setStyle('visibility', 'hidden');
        }
        i+=1;
	}
	
}


//-->
</script>

<% request.setAttribute("tab", 1); %>
<%@ include file="/header.jsp" %>


<%@page import="ar.edu.itba.bundundu.CalendarServlet"%>
<table width="80%" border=1 cellpadding="5">
<tbody>
<tr>
<th valign=center align=middle width="14%">Sunday</th>
<th valign=center align=middle width="14%">Monday</th>
<th valign=center align=middle width="14%">Tuesday</th>
<th valign=center align=middle width="14%">Wednesday</th>
<th valign=center align=middle width="14%">Thursday</th>
<th valign=center align=middle width="14%">Friday</th>
<th valign=center align=middle width="14%">Saturday</th>
</tr>


<%
	boolean var;
	int day;
	List <BundunduEvent> events=(List<BundunduEvent>)request.getAttribute("events");
	BundunduEvent event;
	
/*	if(events!=null){
		for(int i=0; i<events.size(); i++){
			out.println(events.get(i).getTitle().getPlainText());
			out.println("<br/>");
			out.println(events.get(i).getAuthors().get(0).getName());
			out.println("<br/>");                        
			out.println(events.get(i).getUpdated());
			out.println("<br/>");   
			out.println(events.get(i).getTimes().get(0).getStartTime());
			out.println("<br/>");   
			out.println(events.get(i).getTimes().get(0).getEndTime());
			out.println("<br/>");   
			//out.println(events.get(i).getLocations().get(0).getValueString());
			
		}	
	}else{
		out.println("eventos nulo");
	}
*/
%>

<c:set var="count_day" value="${1}"/>
<c:forEach var="i" begin="1" end="6" step="1" varStatus ="status">
	<tr>
	
	<c:forEach var="j" begin="1" end="7" step="1">
		<td vAlign=top align=left width="14%" >
			<c:if test="${(i==1 && j>=first) || (i>1 && count_day<=days)}">
				<c:out value="${count_day}"/>
				
				<jsp:useBean id="count_day" type="java.lang.Number" />
				<%
					while((event=CalendarServlet.getEntry(events, count_day.intValue()))!=null)
					{				
						out.println("<div class='event' id='"+ event.getCalendarId()+"'  style='background-color:" + event.getColor() + "'>" + event.getEventEntry().getTitle().getPlainText() + "</div>");
					}
				%>
				<c:set var="count_day" value="${count_day+1}"/>
			</c:if>
			<br><br><br><br>
		</td>
	</c:forEach>
	</tr>
</c:forEach>
</tbody>
</table>

<div class="calendars">
	<fieldset title='Calendars'>
		<c:forEach items="${calendars}" var="cal">
			<input type='checkbox' checked='checked' onchange='showEvent("<c:out value="${cal.id}"/>");' /><c:out value="${cal.title.plainText}"/><br/>
		</c:forEach>
	</fieldset>
</div>

